﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using App.Domain.Contracts;
using App.Model;

namespace App.Domain.Models {
    public static class ViewModelExtensions {

        public static Company ConvertToEntity(this ICreateCompanyCommand companyForm) {
            if (companyForm == null)
                return null;

            var company = new Company {
                Id = companyForm.Id,
                CompanyName = companyForm.CompanyName,
                AnotherName = companyForm.AnotherName,
                ShortName = companyForm.ShortName,
                Shortcut = companyForm.Shortcut,
                Industry = companyForm.Industry,
                CompanyType = companyForm.CompanyType,
                Employees = companyForm.Employees,
                BusinessLicense = companyForm.BusinessLicense,
                RegisteredCapital = companyForm.RegisteredCapital,
                EstablishedOn = companyForm.EstablishedOn,
                Overview = companyForm.Overview,
                Business = companyForm.Business,
                Province = companyForm.Province,
                City = companyForm.City,
                Address = companyForm.Address,
                PostalCode = companyForm.PostalCode,
                Contact = companyForm.Contact,
                Tel = companyForm.Tel,
                Fax = companyForm.Fax,
                Email = companyForm.Email,
                WebSite = companyForm.WebSite,
                Park = companyForm.Park,
                IsGroup = companyForm.IsGroup,
                ParentCompanyId = companyForm.ParentCompanyId,
                EnableShortName = companyForm.EnableShortName,
                EnableAnotherName = companyForm.EnableAnotherName,
                DailySigned = companyForm.DailySigned,
                TemplateId = companyForm.TemplateId,
                DateCreated = companyForm.DateCreated,
                LastUpdated = companyForm.LastUpdated
            };

            return company;
        }

        public static Recruiter ConvertToEntity(this ICreateRecruiterCommand recruiterForm) {
            if (recruiterForm == null)
                return null;

            var recruiter = new Recruiter {
                Id = recruiterForm.Id,
                UserName = recruiterForm.UserName,
                Password = recruiterForm.Password,
                PasswordSalt = recruiterForm.PasswordSalt,
                PasswordFormat = recruiterForm.PasswordFormat,
                FullName = recruiterForm.FullName,
                JobTitle = recruiterForm.JobTitle,
                Email = recruiterForm.Email,
                Phone = recruiterForm.Phone,
                Ext = recruiterForm.Ext,
                Fax = recruiterForm.Fax,
                Mobile = recruiterForm.Mobile,
                IsManager = recruiterForm.IsManager,
                Active = recruiterForm.Active,
                Deleted = recruiterForm.Deleted,
                ExpiryDate = recruiterForm.ExpiryDate,
                DateCreated = recruiterForm.DateCreated,
                LastUpdated = recruiterForm.LastUpdated,
                CompanyId = recruiterForm.CompanyId,
            };

            return recruiter;
        }

        public static JobPosition ConvertToEntity(this ICreateJobPositionCommand jobPositionForm) {
            if (jobPositionForm == null)
                return null;

            var jobPosition = new JobPosition {
                Id = jobPositionForm.Id,
                JobTitle = jobPositionForm.JobTitle,
                ReferenceNumber = jobPositionForm.ReferenceNumber,
                JobType = jobPositionForm.JobType,
                Responsibilities = jobPositionForm.Responsibilities,
                Qualifications = jobPositionForm.Qualifications,
                Department = jobPositionForm.Department,
                WorkingHours = jobPositionForm.WorkingHours,
                Payment = jobPositionForm.Payment,
                Welfare = jobPositionForm.Welfare,
                Vacation = jobPositionForm.Vacation,
                Wants = jobPositionForm.Wants,
                Province = jobPositionForm.Province,
                City = jobPositionForm.City,
                SalaryRange = jobPositionForm.SalaryRange,
                MonthlySalary = jobPositionForm.MonthlySalary,
                Major1 = jobPositionForm.Major1,
                Major2 = jobPositionForm.Major2,
                EducationLevel = jobPositionForm.EducationLevel,
                YearsOfExperience = jobPositionForm.YearsOfExperience,
                LanguageLevel = jobPositionForm.LanguageLevel,
                CareerLevel = jobPositionForm.CareerLevel,
                MinAge = jobPositionForm.MinAge,
                MaxAge = jobPositionForm.MaxAge,
                ApplyType = jobPositionForm.ApplyType,
                RecruitingUrl = jobPositionForm.RecruitingUrl,
                SelectProcess = jobPositionForm.SelectProcess,
                Address = jobPositionForm.Address,
                PostalCode = jobPositionForm.PostalCode,
                Contact = jobPositionForm.Contact,
                Email = jobPositionForm.Email,
                Tel = jobPositionForm.Tel,
                ApplyByGraduate = jobPositionForm.ApplyByGraduate,
                IsExchange = jobPositionForm.IsExchange,
                StartDate = jobPositionForm.StartDate,
                Reposted = jobPositionForm.Reposted,
                EndDate = jobPositionForm.EndDate,
                IsPending = jobPositionForm.IsPending,
                IsHot = jobPositionForm.IsHot,
                Views = jobPositionForm.Views,
                Applies = jobPositionForm.Applies,
                Clicks = jobPositionForm.Clicks,
                IsPosted = jobPositionForm.IsPosted,
                Source = jobPositionForm.Source,
                DateCreated = jobPositionForm.DateCreated,
                LastUpdated = jobPositionForm.LastUpdated,
                ModifiedBy = jobPositionForm.ModifiedBy,
                Deleted = jobPositionForm.Deleted,
                CompanyId = jobPositionForm.CompanyId,
            };

            return jobPosition;
        }

        public static Application ConvertToEntity(this ICreateApplicationCommand applicationForm) {
            if (applicationForm == null)
                return null;

            var application = new Application {
                Id = applicationForm.Id,
                JobPositionId = applicationForm.JobPositionId,
                CompanyId = applicationForm.CompanyId,
                WorkingLocation = applicationForm.WorkingLocation,
                ResumeId = applicationForm.ResumeId,
                CoverLetter = applicationForm.CoverLetter,
                DesiredSalary = applicationForm.DesiredSalary,
                Others = applicationForm.Others,
                StartDate = applicationForm.StartDate,
                EndDate = applicationForm.EndDate,
                DateApplied = applicationForm.DateApplied,
                JobseekerId = applicationForm.JobseekerId,
                Source = applicationForm.Source,
                Status = applicationForm.Status,
            };

            return application;
        }

        public static Bulletin ConvertToEntity(this ICreateBulletinCommand bulletinForm) {
            if (bulletinForm == null)
                return null;

            var bulletin = new Bulletin {
                Id = bulletinForm.Id,
                Title = bulletinForm.Title,
                Body = bulletinForm.Body,
                Published = bulletinForm.Published,
                DatePosted = bulletinForm.DatePosted,
                DateCreated = bulletinForm.DateCreated,
                LastUpdated = bulletinForm.LastUpdated,
                ModifiedBy = bulletinForm.ModifiedBy,
            };

            return bulletin;
        }

        public static Candidate ConvertToEntity(this ICreateCandidateCommand candidateForm) {
            if (candidateForm == null)
                return null;

            var candidate = new Candidate {
                Id = candidateForm.Id,
                TagId = candidateForm.TagId,
                JobPositionId = candidateForm.JobPositionId,
                ResumeId = candidateForm.ResumeId,
                CoverLetter = candidateForm.CoverLetter,
                DesiredSalary = candidateForm.DesiredSalary,
                Others = candidateForm.Others,
                DateApplied = candidateForm.DateApplied,
                DateReceived = candidateForm.DateReceived,
                Rating = candidateForm.Rating,
                Notes = candidateForm.Notes,
                Status = candidateForm.Status,
                Deleted = candidateForm.Deleted,
                LastUpdated = candidateForm.LastUpdated,
                LastVisited = candidateForm.LastVisited,
                CompanyId = candidateForm.CompanyId,
                ModifiedBy = candidateForm.ModifiedBy,
            };

            return candidate;
        }

        public static Certification ConvertToEntity(this ICreateCertificationCommand certificationForm) {
            if (certificationForm == null)
                return null;

            var certification = new Certification {
                Id = certificationForm.Id,
                CertificationName = certificationForm.CertificationName,
                QualifiedCertification = certificationForm.QualifiedCertification,
                DateQualified = certificationForm.DateQualified,
                Score = certificationForm.Score,
                ResumeId = certificationForm.ResumeId,
                DateCreated = certificationForm.DateCreated,
                LastUpdated = certificationForm.LastUpdated,
            };

            return certification;
        }

        public static Education ConvertToEntity(this ICreateEducationCommand educationForm) {
            if (educationForm == null)
                return null;

            var education = new Education {
                Id = educationForm.Id,
                SchoolName = educationForm.SchoolName,
                Major1 = educationForm.Major1,
                Major2 = educationForm.Major2,
                OtherMajor = educationForm.OtherMajor,
                StartDate = educationForm.StartDate,
                EndDate = educationForm.EndDate,
                EducationLevel = educationForm.EducationLevel,
                IsAbroad = educationForm.IsAbroad,
                SchoolTag = educationForm.SchoolTag,
                Notes = educationForm.Notes,
                ResumeId = educationForm.ResumeId,
                DateCreated = educationForm.DateCreated,
                LastUpdated = educationForm.LastUpdated,
            };

            return education;
        }

        public static JobCategory ConvertToEntity(this ICreateJobCategoryCommand jobCategoryForm) {
            if (jobCategoryForm == null)
                return null;

            var jobCategory = new JobCategory {
                Id = jobCategoryForm.Id,
                JobPositionId = jobCategoryForm.JobPositionId,
                Category = jobCategoryForm.Category,
            };

            return jobCategory;
        }

        public static News ConvertToEntity(this ICreateNewsCommand newsForm) {
            if (newsForm == null)
                return null;

            var news = new News {
                Id = newsForm.Id,
                Title = newsForm.Title,
                Tab = newsForm.Tab,
                Url = newsForm.Url,
                Short = newsForm.Short,
                Full = newsForm.Full,
                Published = newsForm.Published,
                PostedOn = newsForm.PostedOn,
                PostedBy = newsForm.PostedBy,
            };

            return news;
        }

        public static Picture ConvertToEntity(this ICreatePictureCommand pictureForm) {
            if (pictureForm == null)
                return null;

            var picture = new Picture {
                Id = pictureForm.Id,
                CompanyId = pictureForm.CompanyId,
                Title = pictureForm.Title,
                PictureBinary = pictureForm.PictureBinary,
                ImageUrl = pictureForm.ImageUrl,
                MimeType = pictureForm.MimeType,
                Width = pictureForm.Width,
                Height = pictureForm.Height,
                Size = pictureForm.Size,
                SortOrder = pictureForm.SortOrder,
                IsLogo = pictureForm.IsLogo,
            };

            return picture;
        }

        public static Resume ConvertToEntity(this ICreateResumeCommand resumeForm) {
            if (resumeForm == null)
                return null;

            var resume = new Resume {
                Id = resumeForm.Id,
                ResumeName = resumeForm.ResumeName,
                ReferenceNumber = resumeForm.ReferenceNumber,
                FullName = resumeForm.FullName,
                Gender = resumeForm.Gender,
                BirthDate = resumeForm.BirthDate,
                IDCard = resumeForm.IDCard,
                Avatar = resumeForm.Avatar,
                Tel = resumeForm.Tel,
                Mobile = resumeForm.Mobile,
                Email = resumeForm.Email,
                PersonalSite = resumeForm.PersonalSite,
                Province1 = resumeForm.Province1,
                City1 = resumeForm.City1,
                District1 = resumeForm.District1,
                Province2 = resumeForm.Province2,
                City2 = resumeForm.City2,
                District2 = resumeForm.District2,
                Street2 = resumeForm.Street2,
                PostalCode = resumeForm.PostalCode,
                BusLines = resumeForm.BusLines,
                PrivacyStatus = resumeForm.PrivacyStatus,
                CurrentJob = resumeForm.CurrentJob,
                CurrentEmployer = resumeForm.CurrentEmployer,
                Major = resumeForm.Major,
                EducationLevel = resumeForm.EducationLevel,
                YearsOfExperience = resumeForm.YearsOfExperience,
                CareerLevel = resumeForm.CareerLevel,
                Language1 = resumeForm.Language1,
                Level1 = resumeForm.Level1,
                Language2 = resumeForm.Language2,
                Level2 = resumeForm.Level2,
                IsGraduates = resumeForm.IsGraduates,
                PersonalStatement = resumeForm.PersonalStatement,
                DesiredLocation = resumeForm.DesiredLocation,
                DesiredJobType = resumeForm.DesiredJobType,
                CurrentRevenue = resumeForm.CurrentRevenue,
                DesiredSalary = resumeForm.DesiredSalary,
                DesiredOccupation = resumeForm.DesiredOccupation,
                DesiredIndustry = resumeForm.DesiredIndustry,
                DesiredCompanyType = resumeForm.DesiredCompanyType,
                CanStart = resumeForm.CanStart,
                StartOn = resumeForm.StartOn,
                ResumeTag = resumeForm.ResumeTag,
                IsShieldedInsurance = resumeForm.IsShieldedInsurance,
                Integrity = resumeForm.Integrity,
                Views = resumeForm.Views,
                Notes = resumeForm.Notes,
                DateCreated = resumeForm.DateCreated,
                LastUpdated = resumeForm.LastUpdated,
                JobseekerId = resumeForm.JobseekerId,
                Revision = resumeForm.Revision,
            };

            return resume;
        }

        public static Skill ConvertToEntity(this ICreateSkillCommand skillForm) {
            if (skillForm == null)
                return null;

            var skill = new Skill {
                Id = skillForm.Id,
                Subject = skillForm.Subject,
                SkillCode = skillForm.SkillCode,
                Body = skillForm.Body,
                ResumeId = skillForm.ResumeId,
                DateCreated = skillForm.DateCreated,
                LastUpdated = skillForm.LastUpdated,
            };

            return skill;
        }

        public static Tag ConvertToEntity(this ICreateTagCommand tagForm) {
            if (tagForm == null)
                return null;

            var tag = new Tag {
                Id = tagForm.Id,
                TagName = tagForm.TagName,
                Candidates = tagForm.Candidates,
                CompanyId = tagForm.CompanyId,
            };

            return tag;
        }

        public static Training ConvertToEntity(this ICreateTrainingCommand trainingForm) {
            if (trainingForm == null)
                return null;

            var training = new Training {
                Id = trainingForm.Id,
                StartDate = trainingForm.StartDate,
                EndDate = trainingForm.EndDate,
                Institution = trainingForm.Institution,
                Location = trainingForm.Location,
                Course = trainingForm.Course,
                Qualification = trainingForm.Qualification,
                Notes = trainingForm.Notes,
                ResumeId = trainingForm.ResumeId,
                DateCreated = trainingForm.DateCreated,
                LastUpdated = trainingForm.LastUpdated,
            };

            return training;
        }

        public static Work ConvertToEntity(this ICreateWorkCommand workForm) {
            if (workForm == null)
                return null;

            var work = new Work {
                Id = workForm.Id,
                CompanyName = workForm.CompanyName,
                StartDate = workForm.StartDate,
                EndDate = workForm.EndDate,
                CompanyType = workForm.CompanyType,
                Industry = workForm.Industry,
                Department = workForm.Department,
                Category1 = workForm.Category1,
                Category2 = workForm.Category2,
                JobTitle = workForm.JobTitle,
                Description = workForm.Description,
                IsOverseas = workForm.IsOverseas,
                IsShielded = workForm.IsShielded,
                ResumeId = workForm.ResumeId,
                DateCreated = workForm.DateCreated,
                LastUpdated = workForm.LastUpdated,
            };

            return work;
        }
    }
}
